function C_updateNIDisplay(ID)
% UPDATE PLOTTING FOR THE ARDUINO
  
global CG; if nargin < 1 ID = 1; end

if isempty(CG.Display.NI(ID).FIG) | ~ishandle(CG.Display.NI(ID).FIG)   
  C_prepareNIDisplay(ID); end

NAnalogIn = CG.Sessions.NI(ID).NAnalogIn;
NDigitalOut = CG.Sessions.NI(ID).NDigitalOut;

ThreshColors = {[0,0,0],[1,0,0]};

% COMPUTE THE CURRENT TIME-INDICES TO USE
PacketsAcquired = CG.Sessions.NI(ID).PacketsAcquired;
PacketsDisplayed =  CG.Display.NI(ID).PacketsDisplayed ;
if PacketsAcquired > PacketsDisplayed
  cTimeInd  = [PacketsAcquired - PacketsDisplayed+1:PacketsAcquired];
  PreData = [];
else 
  cTimeInd = [1:PacketsAcquired];
  PreData = zeros(PacketsDisplayed - PacketsAcquired,1);
end

% UPDATE THE DIGITAL OUTPUT
for iP = 1:NDigitalOut
  set(CG.Display.NI(ID).DigitalPH(iP),'Color',CG.Display.NI(ID).DigitalColors{CG.Sessions.NI(ID).DOState(iP)+1});
end

% DISPLAY THE MOST RECENT ANALOG DATA
for iP = 1:NAnalogIn
  cData = CG.Data.NI(ID).Analog(cTimeInd,iP);
  if ~isempty(PreData) cData = [PreData;cData]; end
  set(CG.Display.NI(ID).AnalogPH(iP),'YData',cData + CG.Display.NI(ID).AnalogOffset(iP));
  IsGreater = CG.Sessions.NI(ID).AnalogThresholds(iP)>cData(end);
  set(CG.Display.NI(ID).AnalogVal(iP),'String',sprintf('%1.2fV',cData(end)),'Color',ThreshColors{IsGreater+1});
end
cDiff = diff(CG.Data.NI(ID).Time([1,CG.Sessions.NI(ID).PacketsAcquired],1));
cSR = (CG.Sessions.NI(ID).PacketsThisIteration)/CG.Sessions.NI(ID).TimeThisIteration;
set(CG.Display.NI(ID).TimeH,'String',sprintf('Time = %3.2f s , SR = %4.0f Hz ',cDiff,cSR));